;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : strspn.s
;	Function  :
;	       This is strspn function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; strspn
;	return length of maximum initial segment of the 
;	src string (0 terminated) which consists entirely 
;	of characters from the cmp string (0 terminated)
;
; arguments : %r6:src addr, %r7:cmp addr
; return    : %r4:max. length
; comment   : destroy %r9
;*****************************************************

	.section .text
	.align 1
	.global strspn
	.type	strspn,@function

strspn:
	ld.w	%r4, -1			; initialize length
			
strspn_loop:
	add		%r4, 1
	ld.ub	%r10, [%r6]+	; load byte
	cmp		%r10, 0
	jreq	strspn_ret
	ld.w	%r11, %r7		; temp = cmp addr

cmp_loop:
	ld.ub	%r9, [%r11]+	; load byte
	cmp		%r9, %r10
	jreq	strspn_loop
	cmp		%r9, 0			; loop until end of string
	jrne	cmp_loop

strspn_ret:
	ret

